	package com.hz.house.controller;

import com.hz.house.bean.dto.CallHistoryInfo;
import com.hz.house.bean.vo.ShareAddScoreCondition;
import com.hz.house.bean.vo.UserBaseInfo;
import com.hz.house.common.ResultUtil;
import com.hz.house.service.SellManService;
import com.hz.house.token.CurrentUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * <p> 置业顾问相关的服务接口
 * @author lfw
 *
 */
@RestController
@RequestMapping("/api/v2/sellman")
@Api("置业顾问")
@Slf4j
public class SellManController {

	@Autowired
	private SellManService sellManService;

	
	@ApiOperation(value = "点击咨询调用该接口,customerId=用户点击的置业顾问用户id")
	@GetMapping("/getImSellMan")
	public Object getImSellManInfo(Integer customerId) {
		return sellManService.getImSellManInfo(customerId);
	}
	
	@ApiOperation(value = "咨询时获取当前用户的信息和im签名")
	@GetMapping("/getImMyInfo")
	public Object getImCurrentUserInfo() {
		return  sellManService.getImCurrentUserInfo();
	}
	
	@ApiOperation(value = "根据用户的Id判断用户的身份是置业顾问还是普通用户")
	@GetMapping("/getUserRoleById")
	public Object getUserRoleById(Integer customerId, Integer from) {
		return this.sellManService.getUserRoleById(customerId, from);
	}

	@ApiOperation(value = "根据用户的Id修改置业顾问招呼语")
	@GetMapping("/editSellManGreet")
	public Object editSellManGreet(Integer customerId, String greet) {
		return this.sellManService.editSellManGreet(customerId, greet);
	}

	/**
	 * <p> 获取昨日之星置业顾问
	 * @return
	 */
	@ApiOperation(value = "获取昨日之星置业顾问")
	@GetMapping("/getYesterdyStar")
	public Object getYesterdayStar() {
		return this.sellManService.getYesterdayStar();
	}
	
	/**
	 * <p> 获取置业顾问的列表
	 * @return
	 */
	@ApiOperation(value = "置业顾问张列表接口，keyword可以是楼盘名或置业顾问名")
	@GetMapping("/rankList")
	public Object getSellManList(String keyword,Integer page) {
		return this.sellManService.getSellManList(keyword, page);
	}
	
	/**
	 * <p>查询获取用户得身份，普通用户或这职业顾问
	 * @return
	 */
	@ApiOperation(value ="获取该用户得身份，sell_man置业顾问，customer普通用户")
	@GetMapping("/getUserInfo")
	public Object getUserRoleType() {
		return sellManService.getUserRoleType();
	}
	
	/**
	 * <p>分享指定页面用户点击后加分
	 * @return
	 */
	@ApiOperation(value = "分享指定页面用户点击后，给指定置业顾问加积分,socreId加分项的指定id")
	@PostMapping("/addScoreOnSharePage")
	public Object addScoreOnShare(@RequestBody ShareAddScoreCondition sc) {
		return this.sellManService.addScoreOnSharePage(sc);
	}
 
	
	/**
	 * 	置业顾问签到接口
	 * @return
	 */
	@ApiOperation(value = "置业顾问签到接口")
	@GetMapping("/doSign")
	public Object sellmanSign() {
		return this.sellManService.sellmanSign();
	}
	
	
	/**
	 *  查询置业顾问签到数据
	 * @return
	 */
	@ApiOperation(value = "查询置业顾问签到数据")
	@GetMapping("/getSignInfo")
	public Object getSellmanSignInfo() {
		return this.sellManService.getSellmanSignInfo();
	}
	
	/**
	 *  开启七天签到宝箱
	 * @return
	 */
	@ApiOperation(value = "开启置业顾问连续签到七天的宝箱")
	@GetMapping("/openBox7")
	public Object openTreasureBox(Integer boxid) {
		return this.sellManService.openTreasureBox(boxid);
	}
	
	/**
	 * <p> 获取每日任务的完成情况
	 * @return
	 */
	@ApiOperation(value = "获取每日任务的完成情况")
	@GetMapping("/getDailyTask")
	public Object getDailyTaskCount() {
		return this.sellManService.getDailyTaskCounts(CurrentUser.getCurrentUserId());
	}
	
	/**
	 * <p> 给置业顾问点赞
	 * @return
	 */
	@ApiOperation(value = "给置业顾问点赞，一天可以点一次")
	@GetMapping("/doPraise")
	public Object praiseSellMan(Integer sellManCustomerId) {
		return this.sellManService.praiseSellMan(sellManCustomerId);
	}
	
	/**
	 * <p>关注置业顾问
	 * @param sellManCustomerId
	 * @return
	 */
	@ApiOperation(value = "关注置业顾问,isFocus=true,已经关注，调用此接口则取关，isFocus=false,还未关注，调用此接口添加关注")
	@GetMapping("/focusSellman")
	public Object focusSellMan(Integer sellManCustomerId,Boolean isFocus) {
		return this.sellManService.focusSellMan(sellManCustomerId,isFocus);
	}
	
	/**
	 * 查询楼盘下置业顾问信息
	 * @return
	 */
	@ApiOperation(value = "查询楼盘下置业顾问的信息")
	@GetMapping("/getBuildingSellMan")
	public Object getBuildingSellmans(Integer buildingId,Integer page) {
		return this.sellManService.getBuildingSellmans(buildingId, page);
	}
	
	@ApiOperation(value = "获取置业顾问个人积分页面的总积分、活跃度、以及今日积分、今日活跃度")
	@GetMapping("/getScoreLive")
	public Object getScoreAndLive() {
		return this.sellManService.getScoreAndLive(CurrentUser.getCurrentUserId());
	}
	
	@ApiOperation(value = "查询一月的每日积分列表，不分页,yearMonth:2019-09,不传则查询当月")
	@GetMapping("/getMonthDailyScore")
	public Object getMonthScoreList(String yearMonth) {
		return this.sellManService.getMonthScoreList(yearMonth);
	}
	
	@ApiOperation(value = "查询选择时间当天的积分记录，分页哦，每页20条,date=yyyy-MM-dd")
	@GetMapping("/getDailyScoreRecord")
	public Object getDailyScoreRecord(String time,Integer page) {
		return this.sellManService.getDailyScoreRecord(time, page);
	}
	
	@ApiOperation(value = "查询最近30天的活跃度每日列表记录")
	@GetMapping("/getLast30Live")
	public Object getLast30DaysLiveList() {
		return this.sellManService.getLast30DaysLiveList(CurrentUser.getCurrentUserId());
	}
	
	/**
	 * <p>重点接口，小程序启动时，拉取未读消息，同时提交授权后的用户最新头像和昵称
	 * <p>没办法，只能妥协放在这里了
	 * @param info
	 * @return
	 */
	@ApiOperation(value = "获取用户消息中心未读系统消息,以及更新用户基本信息")
	@PostMapping("/getUserMsgAndPostBaseInfo")
	public Object getUserMsgAndPostBaseInfo(@RequestBody UserBaseInfo info) {
		return this.sellManService.getUserMsgAndPostBaseInfo(CurrentUser.getCurrentUserId(),info);
	}
	
	@ApiOperation(value = "获取用户消息中心未读系统消息条")
	@GetMapping("/getCenterNotReadMsgNum")
	public Object getUserCenterNotReadSystemMsgCount() {
		return this.sellManService.getUserCenterNotReadSystemMsgCount(CurrentUser.getCurrentUserId());
	}

	
	@ApiOperation(value = "通知服务端，该用户给置业顾问发了IM通信咨询消息，发送一次，调用一次该接口")
	@GetMapping("/notifyUserSendIm")
	public Object notifyUserSendMsg(Integer sellManCustomerId) {
		 return this.sellManService.notifyUserSendImMsg(sellManCustomerId);
	}

	@ApiOperation(value = "用户给置业顾问拨打电话,调用此接口对电话号码加密，使用加密后的电话号码拨打")
	@GetMapping("/encodePhoneNumber")
	public Object encodePhoneNumber(String localPhoneNumber, Integer sellManCustomerId){
		return this.sellManService.encodePhoneNumber(CurrentUser.getCurrentUserId(),  sellManCustomerId);
	}

	@ApiOperation(value = "置业用户获取通话记录")
	@GetMapping("/callMeHistoryLog")
	public Object callMeHistoryLog(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
													@RequestParam(value = "isAll", required = false, defaultValue = "1") @ApiParam(value = "是否查询全部, 1(true)查询全部, 0(false) 查询未接电话") boolean isAll){
		CallHistoryInfo info = sellManService.callMeHistoryLog(CurrentUser.getCurrentUserId(), isAll, pageIndex);
		return ResultUtil.ok(info);
	}
	
	@ApiOperation(value = "积分兑换财富币")
	@GetMapping("/addCoin")
	public Object scoreConvertCoin(Integer coin) {
		try {
			return this.sellManService.scoreConvertCoin(coin, CurrentUser.getCurrentUserId());
		} catch (Exception e) {
			e.printStackTrace();
			log.error("积分兑换财富币失败",e);
			return ResultUtil.fail(e.getMessage());
		}
	}
	
	@ApiOperation(value = "我的财富币查询接口")
	@GetMapping("/getMyCoin")
	public Object getMyCoin() {
		return this.sellManService.getMyCoin(CurrentUser.getCurrentUserId());
	}
	
	@ApiOperation(value = "查询用户的金币流水,每页15条,recordType=1支出2收入")
	@GetMapping("/getCoinRecord")
	public Object getCoinRecord(Integer page) {
		return this.sellManService.getCoinRecord(page, CurrentUser.getCurrentUserId());
	}
	
	
	@ApiOperation(value = "我要上首页竞价接口")
	@GetMapping("/chuJia")
	public Object chuJia(Integer coin, Integer type) {
		return this.sellManService.chuJia(coin, CurrentUser.getCurrentUserId(), type);
	}
	
	@ApiOperation(value = "查询我要上首页的数据，包括我的剩余金币和当前出价最高的金币数目")
	@GetMapping("/getMaxCoin")
	public Object getMyCoinAndTopCoinNow() {
		return this.sellManService.getMyCoinAndTopCoinNow(CurrentUser.getCurrentUserId());
	}
	
	@ApiOperation(value = "查询今日的竞价记录排行,分页，一页15条")
	@GetMapping("/getChuJiaRecord")
	public Object getTodayChuJiaRecord(Integer page) {
		return this.sellManService.getTodayChuJiaRecord(page, CurrentUser.getCurrentUserId());
	}
	
	
	@ApiOperation(value = "获取置业顾问的主页小程序二维码,以base64字符串方式返回")
	@GetMapping("/getHomeQRCodeBase64")
	public Object getSellManHomePageQRCodeBase64(Integer sellManCustomerId) {
		return this.sellManService.getSellManHomePageQRCodeBase64(sellManCustomerId);
	}
	
	@ApiOperation(value = "获取置业顾问的主页小程序二维码,以二进制流方式返回")
	@GetMapping("/getHomeQRCodeStream")
	public void getSellManHomePageQRCodeStream(Integer sellManCustomerId,HttpServletResponse rep) {
		 this.sellManService.getSellManHomePageQRCodeStream(sellManCustomerId, rep);
	}
	
	
}
